// 新增企业数量

export const companyBarOptions = (data: any) => {
  if (!(data && data.length)) {
    return {}
  }
  let invoiceTimeArr = data.map((item: any) => item.dateStr)

  let invoiceCountArr = data.map((item: any) => item.authOrgCount)
  let invoiceSuccessOrgCountArr = data.map((item: any) => item.invoiceSuccessOrgCount)
  let totalAmtArr = data.map((item: any) => item.unAuthOrgCount)

  let emptyArr: any[] = new Array(totalAmtArr.length).fill(0)

  return {
    legend: {
      top: 16,
      right: 24,
      itemWidth: 6,
      itemGap: 40,
      itemHeight: 6,
      icon: 'circle',
      borderRadius: [3, 3, 3, 3],
      selectedMode: false,
      textStyle: {
        color: '#555D6F'
      }
    },
    grid: {
      left: 64,
      right: 64,
      top: 100,
      bottom: 50
    },
    tooltip: {
      trigger: 'axis',
      axisPointer: {
        type: 'shadow'
      },
      formatter: function (params: any) {
        if (params.length > 1) {
          params.pop()
          let str = ''
          let sum = 0
          params.forEach((item: any) => {
            if (item.data) {
              sum += item.data
            }
            str += `
            <div style='display: flex;align-items: center;margin-top: 4px;'>
              <span style='width: 6px; height:6px;border-radius: 50%;background:${item.color};'></span>
              <span style='color: #555D6F;margin-left:4px;width: 120px;'>${item.seriesName}</span>
              <span style='color: ${item.color}'>${item.data || '0'}个</span>
            </div>
            `
          })

          return (
            `<div style='color: #555D6F;font-weight: 500;'>${params[0].name}</div>
          <div style='display: flex;align-items: center;margin-top: 4px;'>
            <span style='color: #555D6F;margin-left: 10px;width: 120px;'>总共数量</span>
            <span>${sum || '0'}个</span>
          </div>` + str
          )
        } else {
          return `
            <div style='color: #555D6F;font-weight: 500;'>${params[0].name}</div>
            <div style='display: flex;align-items: center;margin-top: 4px;'>
              <span style='color: #555D6F;margin-left: 10px;width: 120px;'>总共数量</span>
              <span>0个</span>
            </div>
            `
        }
      }
    },
    color: ['#D7802E', '#377E43', '#5DC966'],
    dataZoom: [
      {
        type: 'inside',
        show: true
      }
    ],
    xAxis: {
      type: 'category',
      data: invoiceTimeArr,
      axisTick: {
        show: false
      },
      axisLine: {
        show: false,
        lineStyle: {
          color: '#989CA6'
        }
      },
      axisLabel: {
        margin: 10
      },
      boundaryGap: true
    },
    yAxis: [
      {
        type: 'value',
        name: '数量',
        position: 'left',
        minInterval: 1,
        splitLine: {
          lineStyle: {
            color: '#E0E1E6',
            type: 'dashed'
          }
        },
        axisLabel: {
          color: '#979CA7'
        }
      }
    ],
    series: [
      {
        name: '未认证企业数量',
        type: 'bar',
        stack: '总量',
        barMaxWidth: 56,
        barGap: '10%',
        data: totalAmtArr
      },
      {
        name: '已认证企业数量',
        type: 'bar',
        stack: '总量',
        data: invoiceCountArr,
        barMaxWidth: 56,
        barGap: '10%'
      },
      {
        name: '已开票企业数量',
        type: 'bar',
        stack: '总量',
        barMaxWidth: 56,
        barGap: '10%',
        data: invoiceSuccessOrgCountArr
      },
      {
        name: '',
        type: 'bar',
        stack: '总量',
        label: {
          show: true,
          position: 'top',
          formatter: function (p: any, data: any) {
            //这里处理展示的数据和
            let sum = invoiceCountArr[p.dataIndex] + totalAmtArr[p.dataIndex] + invoiceSuccessOrgCountArr[p.dataIndex]
            return sum
          }
        },
        data: emptyArr
      }
    ]
  }
}
